/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.repository.adaptor.method.readproperty;

//import Inspur.Gsp.Caf.Generator.BaseInfoItem.*;
//import Inspur.Gsp.Caf.Generator.ClassMethodGenerator.*;
//import Inspur.Gsp.Caf.Generator.Utils.*;
//import Inspur.Gsp.Cef.Api.Attribute.*;
//import Inspur.Gsp.Cef.Api.Repository.*;
//import Inspur.Gsp.Cef.Repository.*;
//import Inspur.Gsp.Cef.RTGenerator.Common.*;
//import Microsoft.CodeAnalysis.*;
//import Microsoft.CodeAnalysis.CSharp.*;
//import Microsoft.CodeAnalysis.CSharp.Syntax.*;

import com.inspur.edp.caf.generator.baseInfo.ParameterInfo;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.cef.api.attr.*;
import com.inspur.edp.cef.api.repository.readerWriter.ICefReader;
import com.inspur.edp.cef.generator.repository.RepositoryGenUtil;
import com.inspur.edp.cef.generator.repository.dac.DataTypeDacGenContext;
import com.inspur.edp.cef.repository.assembler.AssociationInfo;
import com.inspur.edp.cef.repository.dbcolumninfo.DbColumnInfoCollection;
import org.eclipse.jdt.core.dom.*;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

//      @Override
//      public java.lang.Object readProperty(  java.lang.String propertyName,  com.inspur.edp.cef.api.repository.readerWriter.ICefReader reader){
//		return adaptorItem.readProperty(propertyName, reader);
//		}
public class ReposReadPropertyGenerator extends ClassMethodGenerator {
	public ReposReadPropertyGenerator() {
	}

	public static final String paramPropName = "propertyName";
	public static final String paramReader = "reader";
	private DataTypeDacGenContext dacContext;
	private String nodeCode;
	private boolean isChild;
	private java.util.HashMap<String, String> mappingPropNames;
	private DbColumnInfoCollection dbColumns;
	private ArrayList<AssociationInfo> associationInfo;

	@Override
	protected Block buildMethodBody() {
		Block block = ast.newBlock();
		MethodInvocation methodInvocation = ast.newMethodInvocation();
		methodInvocation.setExpression(ast.newSimpleName("adaptorItem"));
		methodInvocation.setName(ast.newSimpleName("readProperty"));
		methodInvocation.arguments().add(ast.newSimpleName("propertyName"));
		methodInvocation.arguments().add(ast.newSimpleName("reader"));
		ReturnStatement returnStatement = ast.newReturnStatement();
		returnStatement.setExpression(methodInvocation);
		block.statements().add(returnStatement);
		return block;
	}

	@Override
	protected ArrayList<Modifier.ModifierKeyword> getAccessModifiers() {
//		return new java.util.ArrayList<MethodAccessModifier>(java.util.Arrays.asList(new MethodAccessModifier[]{MethodAccessModifier.Public, MethodAccessModifier.Override}));
		ArrayList list = new ArrayList();
		list.add(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
		return list;
	}

	@Override
	protected boolean getIsOverride() {
		return true;
	}

	@Override
	protected String getMethodName() {
		return "readProperty";
	}

	@Override
	protected ArrayList<ParameterInfo> getParameterCollection() {
		ArrayList<ParameterInfo> list = new ArrayList<>();
		list.add(RepositoryGenUtil.createParameterInfo(String.class, paramPropName));
		list.add(RepositoryGenUtil.createParameterInfo(ICefReader.class, paramReader));
		return list;
	}


	@Override
	protected TypeInfo getReturnType() {
		return new TypeInfo(Object.class.getTypeName());
	}
}
